from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

import time

driver = webdriver.Chrome()
#driver.get('https://www.baidu.com/')
#driver.get('https://hao.qq.com/')
#driver.maximize_window()
#ID定位,如果元素有ID，那么肯定全局唯一，可以直接定位元素
#driver.find_element('id','kw').send_keys("六一儿童节")
#driver.find_element('id','su').click()

#name定位
#driver.find_element('name','su').send_keys("王自强")
#driver.find_element('id','su').click()
#driver.find_element(By.NAME,'wd').send_keys('黄河交通学院')
#driver.find_element(By.ID,'su').click()

#link text   适用于可点击的链接
#driver.find_element(By.LINK_TEXT,'新闻').click()

#partial_link_text
#driver.find_element(By.PARTIAL_LINK_TEXT,'hao').click()

#xpath
#driver.find_element(By.XPATH,'//*[@id="kw"]').send_keys("循序渐进")
#driver.find_element(By.XPATH,'//*[@id="su"]').click()

#css
# driver.find_element(By.CSS_SELECTOR,'#kw').send_keys("未来很美")
# driver.find_element(By.CSS_SELECTOR,'#su').submit()
# driver.implicitly_wait(10)#智能等待
#
# driver.find_element(By.CSS_SELECTOR,'#kw').clear()
# time.sleep(3)
#
# driver.find_element(By.CSS_SELECTOR,'#kw').send_keys("丰富自己")
# driver.find_element(By.CSS_SELECTOR,'#su').submit()

#text = driver.find_element(By.CLASS_NAME,'text-color').text
#print(text)

#打印
# title = driver.title
# print(title)
# url = driver.current_url
# print(url)

#设置浏览器框
# driver.find_element(By.CSS_SELECTOR,'#kw').send_keys("好好学习")
# driver.find_element(By.CSS_SELECTOR,'#su').click()
# time.sleep(3)
# driver.set_window_size(400,1000)
# time.sleep(3)

#浏览器后退
# driver.back()
# time.sleep(3)
# #浏览器前进
# driver.forward()
# time.sleep(2)

#浏览器滚动条的操作
# js0 = "var q=document.documentElement.scrollTop=10000" #底端
# driver.execute_script(js0)
# time.sleep(3)
# js1 = "var q=document.documentElement.scrollTop=0" #顶端
# driver.execute_script(js1)

#键盘事件
# driver.get("http://127.0.0.1:88/zentao/user-login.html")
# driver.maximize_window()
#
# driver.find_element(By.ID,'account').send_keys("admin")
# time.sleep(3)
# driver.find_element(By.NAME,'password').send_keys("Wzqiang666888")
# time.sleep(3)
# driver.find_element(By.ID,'submit').click()

driver.get('https://www.baidu.com/')
driver.maximize_window()
driver.find_element(By.CSS_SELECTOR,'#kw').send_keys("好好学习")
time.sleep(3)
#剪切
# driver.find_element(By.ID,'kw').send_keys(Keys.CONTROL,'a')
# time.sleep(3)
# driver.find_element(By.ID,'kw').send_keys(Keys.CONTROL,'x')
# time.sleep(3)
# driver.find_element(By.ID,'kw').send_keys("2022")
# driver.find_element(By.ID,'su').click()

#鼠标事件
b = driver.find_element(By.ID,'su').click()
# ActionChains(driver).double_click(b).perform() #双击
#ActionChains(driver).context_click(b).perform() #右击
#time.sleep(3)

time.sleep(3)
driver.quit()


